package com.mobile.service.impl;

import com.mobile.mapper.CheckGroupCheckItemMapper;
import com.mobile.mapper.CheckGroupMapper;
import com.mobile.mapper.CheckItemMapper;
import com.mobile.pojo.CheckGroup;
import com.mobile.pojo.CheckItem;
import com.mobile.service.CheckGroupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Encounter
 * @date 2024/10/03 18:09<br/>
 */
@Service
@Slf4j
public class CheckGroupServiceImpl implements CheckGroupService
    {
        @Autowired
        private CheckGroupMapper checkGroupMapper;
        @Autowired
        private CheckGroupCheckItemMapper checkGroupCheckItemMapper;
        @Autowired
        private CheckItemMapper checkItemMapper;

        /**
         * 获取由id
         *
         * @param checkGroupId 检查群id
         * @return {@link CheckGroup }
         */
        @Override
        public CheckGroup getById(Integer checkGroupId)
            {
                //根据id获取检查组信息
                CheckGroup checkGroup = checkGroupMapper.getById(checkGroupId);
                
                //获取检查组关联的检查项信息
                List<Integer> checkItemIds = checkGroupCheckItemMapper.findCheckItemIdsByCheckGroupId(checkGroupId);
                if (!checkItemIds.isEmpty())
                    {
                        List<CheckItem> checkItemList = new ArrayList<>();
                        for (Integer checkItemId : checkItemIds)
                            {
                                CheckItem checkItem = checkItemMapper.queryById(checkItemId);
                                checkItemList.add(checkItem);
                            }
                        checkGroup.setCheckItems(checkItemList);
                    }
                return checkGroup;
            }
    }
